package servlet;


import dao.NoticeDao;
import dao.factoty.DaoFactory;
import domain.Notice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "UpdateNoticeServlet", value = "/UpdateNoticeServlet")
public class UpdateNoticeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doGet(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        int id = Integer.parseInt(request.getParameter("id"));
        String title = request.getParameter("title");
        String details = request.getParameter("details");
        NoticeDao noticeDao = DaoFactory.getNoticeDaoInstance();
        try {
            noticeDao.updateNoticeByIde(new Notice(id, title, details));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        response.sendRedirect("/BookStore/NoticeListServlet");
    }
}
